#include "userlistwidget.h"

#include <QMouseEvent>
#include <QMenu>

#include <UserManager/usermanager.h>

void UserListWidget::onItemDoubleClicked(QListWidgetItem *item)
{
    QString account = item->text();
    emit chat(account, true, true);
}

void UserListWidget::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::RightButton) {
        // 获取鼠标点击位置的项
        QListWidgetItem *item = itemAt(event->pos());
        if (item) {
            // 如果点击了一个项，显示菜单
            QMenu menu(this);
            QAction *chatAction = menu.addAction("聊天");
            QAction *removeFriendAction = menu.addAction("删除好友");
            //QAction *addToBlacklistAction = menu.addAction("拉入黑名单");

            QAction *selectedAction = menu.exec(event->globalPosition().toPoint());
            if (selectedAction) {
                if (selectedAction == chatAction) {
                    QString account = item->text();
                    emit chat(account, true, true);
                } else if (selectedAction == removeFriendAction) {
                    QString account = item->text();
                    emit eraseFriend(account);
                }
                //else if (selectedAction == addToBlacklistAction) {
                //    addToBlacklist(item);
                //}
            }
        }
    }
    // 确保其他鼠标事件不被忽略
    QListWidget::mousePressEvent(event);
}

